#include <sxQGL_Viewport.h>

Sx::QtInterface::QGL_Viewport::QGL_Viewport(QWidget* parent, Qt::WFlags flags) : QGLWidget(parent, nullptr, flags) {
	this->setMouseTracking(true);
}

Sx::QtInterface::QGL_Viewport::QGL_Viewport(QWidget* parent, QGL_Viewport* share, Qt::WFlags flags) : QGLWidget(parent, share, flags) {
	this->setMouseTracking(true);
}

Sx::QtInterface::QGL_Viewport::~QGL_Viewport() { /* Do not delete any of the viewportListeners */ }

bool Sx::QtInterface::QGL_Viewport::addViewportListener(QGL_ViewportListener* listener) {
	if ( listener == nullptr ) {
		std::cerr << "[QGL_Viewport:addViewportListener] Error: Cannot add nullptr listener. " << std::endl;
		return false;
	}

	this->viewportListeners.add(listener);
	return true;
}

bool Sx::QtInterface::QGL_Viewport::removeViewportListener(QGL_ViewportListener* listener) {
	if ( listener == nullptr ) {
		std::cerr << "[QGL_Viewport:removeViewportListener] Error: Cannot remove nullptr listener. " << std::endl;
		return false;
	}

	this->viewportListeners.remove(listener);
	return true;
}

void Sx::QtInterface::QGL_Viewport::initializeGL() {
	for ( unsigned int i = 0; i < this->viewportListeners.size(); i++ )
		this->viewportListeners[i]->initializeGL();
}

void Sx::QtInterface::QGL_Viewport::paintGL() {
	for ( unsigned int i = 0; i < this->viewportListeners.size(); i++ )
		this->viewportListeners[i]->paintGL();
}

void Sx::QtInterface::QGL_Viewport::resizeGL(int width, int height) {
	for ( unsigned int i = 0; i < this->viewportListeners.size(); i++ )
		this->viewportListeners[i]->resizeGL(width, height);
}
